package com.mediacloud.app.newsmodule.view

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.WindowManager
import com.mediacloud.app.appfactory.cache.AppConfig
import com.mediacloud.app.assembly.views.FontResizeView
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.reslib.enums.XKey
import com.mediacloud.app.reslib.util.infalte.ImgTxtNewsFontControl
import com.tencent.mmkv.MMKV

class FontResizeDialog(context: Context,var listener: FontResizeView.OnFontChangeListener?=null) : Dialog(context, R.style.ProgressDialogStyle)
{
    var fontSizeCtl:FontResizeView
    var appConfig:AppConfig
    init
    {
        setContentView(R.layout.font_resize_dialog)
        appConfig= AppConfig(context)
        fontSizeCtl=findViewById(R.id.fontSizeCtl)
        findViewById<View>(R.id.clickBgView)?.setOnClickListener { dismiss() }
       /* var imgTxtNewsFontControl=ImgTxtNewsFontControl(context)
        var index=imgTxtNewsFontControl.getWebViewFont(context).ordinal
        fontSizeCtl.setSliderGrade(index)*/
        findViewById<View>(R.id.cancel)?.setOnClickListener { dismiss() }
        fontSizeCtl.setOnFontChangeListener(listener)
        setXXX()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setXXX()
    }

    fun setXXX()
    {
        if (window != null && window!!.attributes != null) {
            val lp = window!!.attributes
            lp.width = WindowManager.LayoutParams.MATCH_PARENT
//            lp.height = WindowManager.LayoutParams.MATCH_PARENT
            window!!.attributes = lp
            setTranslucentStatus()
        }
    }
    fun setTranslucentStatus() {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 全透明实现
            window!!.setStatusBarColor(Color.TRANSPARENT);
        } else {//4.4 全透明状态栏
            getWindow()!!.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

    override fun show() {
        setXXX()
        fontSizeCtl.setSliderGrade(MMKV.defaultMMKV().getInt(XKey.NEWS_FONT_SIZE, 1))
        super.show()

    }
}